//
//  YSDownLoadAllTVC.m
//  YSDownLoadManager_Example
//
//  Created by Kyson on 2018/12/4.
//  Copyright © 2018 kysonyangs. All rights reserved.
//

#import "YSDownLoadAllTVC.h"
#import "YSDownLoadListernDataTool.h"
#import "YSDownloadBookModel.h"
#import "YSDownloadBookCellPresenter.h"

@interface YSDownLoadAllTVC ()

@end

@implementation YSDownLoadAllTVC

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self reloadCache];
}

- (void)viewDidLoad {
    [super viewDidLoad];    
}

- (void)reloadCache {
    
    NSArray<YSDownloadBookModel *> *bookMs = [YSDownLoadListernDataTool getAllDownloadBooks];
    NSMutableArray<YSDownloadBookCellPresenter *> *presenters = [NSMutableArray arrayWithCapacity:bookMs.count];
    for (YSDownloadBookModel *bookM in bookMs) {
        YSDownloadBookCellPresenter *presenter = [YSDownloadBookCellPresenter new];
        presenter.bookModel = bookM;
        [presenters addObject:presenter];
    }

    [self setUpWithDataSouce:presenters getCell:^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
        return [YSDownloadBookCell cellWithTableView:tableView];
    } cellHeight:^CGFloat(id model) {
        return 75;
    } bind:^(YSDownloadBookCell *cell, YSDownloadBookCellPresenter *model) {
        [model bindWithCell:cell];
    }];
}

@end
